a = input().split()
i = ''
f = 1
w = 0
for j in range(3):
    if f == 1:
        f = 1
if f == 1:
    for e in a:
        if e == 'zero':
            i += str(0)
        elif e == 'one':
            i += str(1)
        elif e == 'two':
            i += str(2)
        elif e == 'three':
            i += str(3)
        elif e == 'four':
            i += str(4)
        elif e == 'five':
            i += str(5)
        elif e == 'six':
            i += str(6)
        elif e == 'seven':
            i += str(7)
        elif e == 'eight':
            i += str(8)
        elif e == 'nine':
            i += str(9)
        else:
            print("Wrong input")
            f = 0
            break
        w += 1
if f == 1 and w != 3:
    print("Wrong input")
    f = 0
i = int(i)

midd = 0

p = 0

h = 2

for k in range(1000):
    if f == 1:
        p = 0
        for m in range(2, (k // 2) + 1):
            if k % m == 0:
                h = 0
                p = 1
        if p == 0:
            h = 1
        if (i - midd) > (i - k) and h == 1 and abs(i - midd) > abs(i - k):
            midd = k
if f == 1:
    print(midd)